﻿using System.Configuration;
using System.Web;
using System.Web.Mvc;
using Framework.MVC;
using FrontCenter.Expand;
using FrontCenter.Models;

namespace FrontCenter.Controllers
{
    public class RechargeController : AsyncControllerBase
    {
        #region Filed

        private readonly static string m_user_resource = ConfigurationManager.AppSettings["user_resource"];
        private readonly static string m_vc_resource = ConfigurationManager.AppSettings["verifycode_resource"];
        private const string m_default = "Default";

        #endregion Filed

        //////////////////////

        #region Step1

        public void Step1Async(string code)
        {

            HttpCookie user = Request.Cookies[m_user_resource];
            string current = user != null && !string.IsNullOrWhiteSpace(user.Value) ? user.Value : null ;
            if (string.IsNullOrWhiteSpace(current))
                return;

            GetAccountModel model = new GetAccountModel
            {
                IdentityCode = current,
                Source = Request.UserHostAddress
            };
            ViewData["code"] = current;
            InitModel(model);
        }

        public ActionResult Step1Completed(string name)
        {
            ViewData["name"] = name;
            return View();
        }

        #endregion Index

        #region Step2

        public void Step2Async(string code,string game)
        {
            if (!string.IsNullOrWhiteSpace(game))
            {
                ViewData["game"] = game.Replace("'","");
            }
            HttpCookie user = Request.Cookies[m_user_resource];
            string current = user != null && !string.IsNullOrWhiteSpace(user.Value) ? user.Value : null ;
            if (string.IsNullOrWhiteSpace(current))
                return;
            GetAccountModel model = new GetAccountModel
            {
                IdentityCode = current,
                Source = Request.UserHostAddress
            };
            ViewData["code"] = current;
            InitModel(model);
        }

        public ActionResult Step2Completed(string name)
        {
            if (ViewData["game"] != null && !string.IsNullOrWhiteSpace(ViewData["game"].ToString()))
            {
                ViewData["name"] = name;
                return View();
            }
            else {
                return RedirectToAction("step1");
            }
           
        }

        #endregion Step2

        #region Help

        public ActionResult Help()
        {
            HttpCookie user = Request.Cookies[m_user_resource];
            if (user != null && !string.IsNullOrWhiteSpace(user.Value)) {
                ViewData["code"] = user.Value;
            }
            return View();
        }
        #endregion End
    }
}
